Previous Book Contents Book Index Next

Inside Macintosh: AppleScript Language Guide / Part 2 - AppleScript Language Reference
Chapter 6 - Expressions / Script Properties


Using Script Properties

To see how script properties work, try running the following script, which contains a script property called theCount.

property theCount : 0
set theCount to theCount+1
display dialog "The value of theCount is: " & theCount ÿ 
   as string
The first time you run the script, the value of theCount is set to 0. The Set command adds one to theCount, and the Display Dialog command displays the value of theCount, which is 1.

Now run the script again. The Set command adds 1 to the value of theCount (which is still one because it has not been reset), and the Display Dialog command reports a value of 2. If you run the script a third time, the value of theCount is 3, and so on.

Now save the script as a compiled script. Close the script, and then open and run it without making any changes. The value of theCount is one more than it was before you closed the script.

Finally, recompile the script. (You can do this by making an insignificant change, such as adding a space at the end of a line, and clicking the Check Syntax button.) The value of theCount is set to the initial value in the property definition. The Display Dialog command reports a value of 1.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
13 JUL 1996